home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / mountnfs.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2008-10-14  |  2KB  |  109 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          mountnfs
  4. # Required-Start:    $local_fs
  5. # Required-Stop:
  6. # Should-Start:      $network $portmap nfs-common  udev-mtab
  7. # Default-Start:     S
  8. # Default-Stop:
  9. # Short-Description: Wait for network file systems to be mounted
  10. # Description:       Network file systems are mounted by
  11. #                    /etc/network/if-up.d/mountnfs in the background
  12. #                    when interfaces are brought up; this script waits
  13. #                    for them to be mounted before carrying on.
  14. ### END INIT INFO
  15.  
  16. . /lib/init/vars.sh
  17. . /lib/lsb/init-functions
  18.  
  19. do_wait_async_mount() {
  20.     [ -f /etc/fstab ] || return
  21.     #
  22.     # Read through fstab line by line. If it is NFS, set the flag
  23.     # for mounting NFS file systems. If any NFS partition is found
  24.     # then wait around for it.
  25.     #
  26.  
  27.     exec 9<&0 </etc/fstab
  28.  
  29.     waitnfs=
  30.     while read DEV MTPT FSTYPE OPTS REST
  31.     do
  32.         case "$DEV" in
  33.           ""|\#*)
  34.             continue
  35.             ;;
  36.         esac
  37.         case "$OPTS" in
  38.           noauto|*,noauto|noauto,*|*,noauto,*)
  39.             continue
  40.             ;;
  41.         esac
  42.         case "$FSTYPE" in
  43.           nfs|nfs4|smbfs|cifs|coda|ncp|ncpfs|ocfs2|gfs)
  44.             ;;
  45.           *)
  46.             continue
  47.             ;;
  48.         esac
  49.         case "$MTPT" in
  50.           /usr/local|/usr/local/*)
  51.             ;;
  52.           /usr|/usr/*)
  53.             waitnfs="$waitnfs $MTPT"
  54.             ;;
  55.           /var|/var/*)
  56.             waitnfs="$waitnfs $MTPT"
  57.             ;;
  58.         esac
  59.     done
  60.  
  61.     exec 0<&9 9<&-
  62.  
  63.     # Wait for each path, the timeout is for all of them as that's
  64.     # really the maximum time we have to wait anyway
  65.     TIMEOUT=900
  66.     for mountpt in $waitnfs; do
  67.         log_action_begin_msg "Waiting for $mountpt"
  68.  
  69.         while ! mountpoint -q $mountpt; do
  70.             sleep 0.1
  71.  
  72.             TIMEOUT=$(( $TIMEOUT - 1 ))
  73.             if [ $TIMEOUT -le 0 ]; then
  74.                 log_action_end_msg 1
  75.                 break
  76.             fi
  77.         done
  78.  
  79.         if [ $TIMEOUT -gt 0 ]; then
  80.             log_action_end_msg 0
  81.         fi
  82.     done
  83. }
  84.  
  85. case "$1" in
  86.     start)
  87.         # Using 'no !=' instead of 'yes =' to make sure async nfs
  88.         # mounting is the default even without a value in
  89.         # /etc/default/rcS
  90.         if [ no != "$ASYNCMOUNTNFS" ] ; then
  91.                 do_wait_async_mount
  92.         else
  93.                 FROMINITD=yes /etc/network/if-up.d/mountnfs
  94.         fi
  95.         ;;
  96.     restart|reload|force-reload)
  97.         echo "Error: argument '$1' not supported" >&2
  98.         exit 3
  99.         ;;
  100.     stop)
  101.         ;;
  102.     *)
  103.         echo "Usage: $0 start|stop" >&2
  104.         exit 3
  105.         ;;
  106. esac
  107.  
  108. : exit 0
  109.